#include <iostream>
#include <cassert>
#include <pthread.h>
#include <unistd.h>

using namespace std;

int cnt = 0;

string shared()
{
    return "我是共享方法";
}

void* thread_routine(void* args)
{
    const char* name = (const char*)args;
    while(true)
    {
        cout << "我是新线程，name：" << name << shared() << "cnt : " << cnt++ << " &cnt : " << &cnt << endl;
        sleep(1);
    }
    return nullptr;
}

int main()
{
    pthread_t tid;
    int n = pthread_create(&tid,nullptr,thread_routine,(void *)"thread one");
    assert(n == 0);
    (void)n;

    while(true)
    {
        cout << "我是主线程，我正在运行" << shared() << "cnt : " << cnt << " &cnt : " << &cnt << endl;
        sleep(1);
    }
    return 0;
}
